package cn.itcast.test;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.junit.Test;

import java.util.List;

public class Demo {
    @Test
    public void testQueryBeans() throws Exception {
        // 1.连接Solr服务器
        HttpSolrServer server = new HttpSolrServer("http://localhost:8080/solr/core2");
        // 2.创建查询对象：SolrQuery
        SolrQuery query = new SolrQuery("title:iphone");
        // 3.执行查询,获取响应
        QueryResponse response = server.query(query);

        // 4.从响应中抽取实体结果
        List<Item> list = response.getBeans(Item.class);
        // 打印总条数：
        System.out.println("本次共搜索到" + list.size() + "条数据。");
        // 遍历集合
        for (Item item : list) {
            System.out.println(item);
        }
    }

}
